using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;

namespace Code5Systems.FormMaster.Data
{

	public abstract class DataProvider
	{
		
		
#region Shared/Static Methods
		
		// singleton reference to the instantiated object
		private static DataProvider objProvider = null;
		
		// constructor
		static DataProvider()
		{
			CreateProvider();
		}
		
		// dynamically create provider
		private static void CreateProvider()
		{
			objProvider = (DataProvider) (DotNetNuke.Framework.Reflection.CreateObject("data", "Code5Systems.FormMaster.Data", ""));
		}
		
		// return the provider
		public static DataProvider Instance()
		{
			return objProvider;
		}
		
#endregion
		
#region Properties
		
		public abstract string ConnectionString {get;}
		public abstract string ObjectQualifier {get;}
		
#endregion
		
#region Form Methods
		public abstract IDataReader GetForm(int moduleId);
		public abstract IDataReader ListForm();
		
		public abstract int AddForm(int portalID, int moduleID, string fromName, byte emailFromAction, string fromAddress, string emailSendFromControl, string bccAddress, byte emailSendAction, string emailSendTo, string emailSendToControl, bool saveData, byte tableColumns, byte tableRows, string tableClass, byte labelPosition, bool showCcMe, string emailCcMeControl, string connectionString, string formQuery, bool useCaptcha, string captchaCharacters, bool useExtTable, string ExtIdentityColumn, string extTableConnStr, string extTableName, byte replyToAction, string replyTo, string replyToControl, string formDefinition, int createdByID, bool ExtTableForEachPage);
		
		public abstract void UpdateForm(int moduleID, string fromName, byte emailFromAction, string fromAddress, string emailSendFromControl, string bccAddress, byte emailSendAction, string emailSendTo, string emailSendToControl, bool saveData, byte tableColumns, byte tableRows, string tableClass, byte labelPosition, bool showCcMe, string emailCcMeControl, string connectionString, string formQuery, bool useCaptcha, string captchaCharacters, bool useExtTable, string ExtIdentityColumn, string extTableConnStr, string extTableName, byte replyToAction, string replyTo, string replyToControl, string formDefinition, int lastModifiedByID, bool ExtTableForEachPage);
		
		public abstract void DeleteForm(int moduleID);
		public abstract void UpdateFormDefinition(int moduleId, string formDefinition, int lastModifiedById);
		public abstract bool HasUserPosted(int moduleId, int userId);
		public abstract DataTable ExecuteSQL(string connectionString, string query);
		public abstract DataSet ExecuteDataSet(string connectionString, string query);
		public abstract IDataReader ExecuteDataReader(string connString, string query);
#endregion
		
#region FormData Methods
		public abstract IDataReader GetFormData(int formDataID, int moduleId);
		public abstract IDataReader ListFormData(int moduleId, DateTime dtStart, DateTime dtEnd, int pageNum, int pageSize);
		public abstract IDataReader ListFormDataExt(int moduleId, DateTime dtStart, DateTime dtEnd, int pageNum, int pageSize);
		public abstract int AddFormData(int formID, int portalID, int moduleID, string formData, int extTableRowId, int createdByID, SqlTransaction objTransaction = null);
		public abstract void UpdateFormData(int formDataId, int formID, int portalID, int moduleID, string formData, int extTableRowId, int lastModifiedByID, SqlTransaction objTransaction = null);
		public abstract void DeleteFormDataRange(int moduleId, DateTime dtStart, DateTime dtEnd, SqlTransaction objTransaction = null);
		public abstract void DeleteFormData(int moduleId, int formDataId, SqlTransaction objTransaction = null);
		public abstract int AddExtTableData(string sql, List<Code5Systems.FormMaster.Business.FormMappingInfo> alMappings, string connString, CultureInfo userCulture);
		public abstract void UpdateExternalTable(string sql, List<Code5Systems.FormMaster.Business.FormMappingInfo> alMappings, string connString, CultureInfo userCulture);
		public abstract void DeleteExternalTable(string sql, string connString);
		public abstract IDataReader GetExtIdByDate(int moduleId, DateTime dtStart, DateTime dtEnd);
		public abstract void SetExtTableIdNull(int moduleId);
		public abstract void SetPageExtTableIdNull(int formID, int pageNum);
#endregion
		
#region FormFileData Methods
		public abstract IDataReader GetFormFileData(int fileDataId);
		public abstract IDataReader ListFormFileData();
		public abstract IDataReader GetFormFileDataByFormData(int formDataID);
		public abstract IDataReader GetFormFileDataByControlId(int formDataId, string controlId);
		public abstract int AddFormFileData(int formDataId, int portalId, int moduleId, string controlId, string contentType, int contentLegth, string filePath, string origFileName, string fileName, bool inDB, byte[] fileData, int createdByID, SqlTransaction objTransaction = null);
		public abstract void UpdateFormFileData(int fileDataId, int formDataId, string contentType, int contentLegth, string filePath, string origFileName, string fileName, bool inDB, byte[] fileData, int lastModifiedByID, SqlTransaction objTransaction = null);
		public abstract void DeleteFormFileData(int fileDataId, SqlTransaction objTransaction = null);
		public abstract IDataReader GetFilesByModuleID(int moduleId);
		public abstract IDataReader GetFormDataToCopy(int moduleId, string idCsv);
		public abstract int GetFormDataToCopyCount(int moduleId, string idCsv);
#endregion
		
#region Web Service Methods
		public abstract IDataReader GetWsFormData(int formDataId, string moduleIds, DateTime dtStart, DateTime dtEnd);
#endregion
		
#region FormMapping Methods
		public abstract IDataReader GetFormMappingByForm(int formID);
		public abstract IDataReader GetFormMappingByPage(int formID, int pageNum);
		public abstract int AddFormMapping(int formID, string formField, string tableField, string dataType, int length, byte prec, byte scale, string nullable, int pageNum);
		public abstract void DeleteFormMappings(int formID);
		public abstract void DeleteFormMappingsByPage(int formID, int pageNum);
#endregion
		
#region FormFieldRules Methods
		public abstract IDataReader GetFormFieldRulesByForm(int formID);
		public abstract int AddFormFieldRules(int formID, string sourceField, string sourceFieldName, string containsValue, byte fieldType, string formFields);
		public abstract void DeleteFormFieldRules(int fieldRuleID);
		public abstract void DeleteFormFieldRulesByForm(int formID);
#endregion
		
#region FormPages Methods
		
		public abstract IDataReader GetFormPage(int formPageID);
		public abstract IDataReader ListFormPages();
		
		public abstract int AddFormPage(int formID, int pageNum, byte tableColumns, byte tableRows, byte labelPosition, string title, string shortName, string pageData, bool useTitle, string ExtIdentityColumn, string ExtTableConnStr, string ExtTableName, int createdByID, DateTime createdDate, int lastModifiedByID, DateTime lastModifiedDate);
		
		public abstract void UpdateFormPage(int formPageID, int formID, int pageNum, byte tableColumns, byte tableRows, byte labelPosition, string title, string shortName, string pageData, bool useTitle, string ExtIdentityColumn, string ExtTableConnStr, string ExtTableName, int createdByID, DateTime createdDate, int lastModifiedByID, DateTime lastModifiedDate);
		
		public abstract void DeleteFormPage(int formPageID);
		public abstract void DeleteFormPageByFormID(int formID);
		public abstract void DeleteFormPageByPageNum(int formID, int pageNum);
		public abstract IDataReader GetFormPagesByFormID(int formID);
#endregion
		
#region Global Methods
		
		public abstract IDataReader GetGlobal(int globalID);
		
		public abstract IDataReader GetGlobalByKey(string itemKey);
		
		public abstract IDataReader ListGlobals();
		
		public abstract int AddGlobal(string itemKey, string itemValue);
		
		public abstract void UpdateGlobal(int globalID, string itemKey, string itemValue);
		
		public abstract void DeleteGlobal(int globalID);
		
#endregion
		
	}
	
}


